package com.clx.chat.controller;

import com.clx.chat.service.MessageService;
import com.clx.common.controller.BaseController;

import com.clx.common.domain.entity.Message;
import com.clx.common.domain.vo.AjaxResult;
import com.clx.common.domain.vo.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Message)表控制层
 *
 * @author clx
 * @since 2025-02-23 10:12:39
 */
@RestController
@RequestMapping("message")
@RequiredArgsConstructor
public class MessageController extends BaseController {
    /**
     * 依赖注入
     */
    private final MessageService messageService;

    /**
     * 查询列表
     */
    
    @GetMapping("/list")
    public TableDataInfo list(Message message) {
        List<Message> list = messageService.selectMessageList(message);
        return getDataTable(list);
    }

    /**
     * 获取详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(messageService.selectMessageById(id));
    }

    /**
     * 新增数据
     */
    @PostMapping
    public AjaxResult add(@RequestBody Message message) {
        return toAjax(messageService.insertMessage(message));
    }

    /**
     * 修改数据
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Message message) {
        return toAjax(messageService.updateMessage(message));
    }

    /**
     * 删除数据
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(messageService.deleteMessageByIds(ids));
    }


    /**
     * 查询用户所有的聊天记录
     */
    @GetMapping("/all")
    public AjaxResult all(@RequestParam("userSelf") Integer userSelf,@RequestParam("userOther") Integer userOther){
        return messageService.all(userSelf,userOther);
    }
}
